import React from 'react'
import PropTypes from 'prop-types'


class Vote extends React.Component {
  static defaultProps = {
    num: 0,
  }
  static propTypes = {
    title: PropTypes.string.isRequired,
    num: PropTypes.number,
  }

  state = {
    popNum: 10,

  }

  constructor(props) {
    super(props)
  }

  render() {
    let { title } = this.props
    console.log('render: ', this.state)
    // console.log('this::: ', this)
    return <>
      <div>{title}</div>
      <div>
        <div>支持人数：{this.state.popNum}</div>
        <button onClick={() => { this.setState({ popNum: this.state.popNum + 1 }) }}>修改状态</button>
      </div>
    </>
  }

  componentDidMount() {
    console.log('componentDidMount')
  }

  UNSAFE_componentWillMount() {
    console.log('componentWillMount')
  }

  shouldComponentUpdate(nextProps, nextState) {
    console.log('shouldComponentUpdate: ', this.state, nextState)
    return true
  }

  UNSAFE_componentWillUpdate(nextProps, nextState) {
    console.log('componentWillUpdate: ', this.state, nextState)
  }

  componentDidUpdate() {
    console.log('componentDidUpdate: ', this.state)
  }
}

export default Vote